# 清理 VS Code 扩展缓存并重新编译

Write-Host "🧹 Cleaning cache and build artifacts..." -ForegroundColor Yellow

# 1. 清理 webpack 缓存
if (Test-Path "node_modules\.cache") {
    Remove-Item -Path "node_modules\.cache" -Recurse -Force
    Write-Host "✓ Cleared webpack cache" -ForegroundColor Green
}

# 2. 清理编译输出
if (Test-Path "dist") {
    Remove-Item -Path "dist" -Recurse -Force
    Write-Host "✓ Cleared dist folder" -ForegroundColor Green
}

# 3. 清理 VS Code 扩展主机缓存
$vscodeCache = "$env:APPDATA\Code\CachedExtensions"
if (Test-Path $vscodeCache) {
    Remove-Item -Path $vscodeCache -Recurse -Force -ErrorAction SilentlyContinue
    Write-Host "✓ Cleared VS Code extension cache" -ForegroundColor Green
}

# 4. 重新编译
Write-Host ""
Write-Host "🔨 Recompiling extension..." -ForegroundColor Yellow
npm run compile

if ($LASTEXITCODE -eq 0) {
    Write-Host ""
    Write-Host "✅ Build completed successfully!" -ForegroundColor Green
    Write-Host ""
    Write-Host "📝 Next steps:" -ForegroundColor Cyan
    Write-Host "  1. Completely close ALL VS Code windows"
    Write-Host "  2. Reopen VS Code"
    Write-Host "  3. Press F5 to start debugging"
    Write-Host ""
} else {
    Write-Host ""
    Write-Host "❌ Build failed!" -ForegroundColor Red
}
